package Jdbc.Dao;

import Jdbc.Domain.User;
import Jdbc.test.JDBCTest;
import utils.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 冷 on 2017/9/12.
 */
public class UserDao {
    Connection conn=JDBCUtils.getConnection();
    Statement sta = conn.createStatement();


    public UserDao() throws SQLException {
    }

    public boolean insert() throws SQLException {
          String sql ="insert into user values(,'j','135','1@qq.com','123456');";
        ResultSet set = sta.executeQuery(sql);
          return true;

      }
      public boolean del() throws SQLException {
          String sql ="delete from user where name='j'";
          ResultSet set = sta.executeQuery(sql);
          return true;
      }
      public List<User> select() throws SQLException {
          ArrayList list = new ArrayList();
          String sql = "select * from user";
          ResultSet set = sta.executeQuery(sql);
          while (set.next()){
              User hhh = new User();
              hhh.setId(set.getInt("Id"));
              hhh.setPassword(set.getString("password"));
              hhh.setUsername(set.getString("username"));
              hhh.setEmail(set.getString("email"));
              hhh.setPhone(set.getInt("phone"));
              list.add(hhh);
              list.add("\n");
              //list.add(set.getString()+","+set.getString(2)+","+set.getString(3)+","+set.getString(4)+","+set.getString(5));
              //System.out.println(set.getString(1)+","+set.getString(2)+","+set.getString(3)+","+set.getString(4)+","+set.getString(5));
          }
          return list;

      }
      public void change(){

      }

}
